home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / JOHNLOVE / C_SOURCE / CDEFAULT.C next >
Text File  |  1992-01-25  |  3KB  |  121 lines

  1. /* ---------------------------
  2. ** "CDefaultButton.c"
  3. **
  4. ** from SPLAsh Resources
  5. ** "THINKin' CaP", Winter 1991
  6. ** --------------------------- */
  7.  
  8.  
  9.  
  10.  
  11. #include <CPaneBorder.h>
  12.  
  13. #include "CDefaultButton.h"
  14. #include "GrayMatters.h"
  15.  
  16.  
  17. #define        CHAR_Return            13        /* Default button responds to the */
  18. #define        CHAR_Enter            3        /*   <Return> and <Enter> keys      */
  19.  
  20.  
  21.  
  22. void    CDefaultButton::IDefaultButton (short CNTLid, CView *anEnclosure,
  23.                                         CBureaucrat    *aSupervisor)    {
  24.  
  25.  
  26.     IButton(CNTLid, anEnclosure, aSupervisor);
  27.  
  28. }    /* IDefaultButton */
  29.  
  30.  
  31.  
  32. void    CDefaultButton::DoKeyDown (char theChar, Byte keyCode,
  33.                                    EventRecord *macEvent)        {
  34.  
  35.  
  36.     if ( ((theChar == CHAR_Return) || (theChar == CHAR_Enter)) && IsActive() )
  37.                  SimulateClick();
  38.     else        inherited::DoKeyDown(theChar, keyCode, macEvent);
  39.  
  40. }    /* DoKeyDown */
  41.  
  42.  
  43.  
  44. void    CDefaultButton::SetDefault (Boolean fDefault)    {
  45.  
  46.         short    roundCorner;
  47.         
  48.         
  49.     inherited::SetDefault(fDefault);
  50.     
  51.     roundCorner = Max(height/2, 16);
  52.     itsBorder->SetRounding(roundCorner, roundCorner);
  53.     
  54. }    /* SetDefault */
  55.  
  56.  
  57.  
  58. void    CDefaultButton::Draw (Rect    *area)    {
  59.  
  60.         LongRect        enclAperture;
  61.         Rect            windRect, defRect;
  62.         PenState        savePenState;
  63.         RGBColor        saveForeColor;
  64.         short            roundCorner;
  65.         AuxCtlHandle    acHndl;
  66.         CCTabHandle        ccTable;
  67.         Boolean            portHasColor;
  68.     
  69.  
  70.     // inherited method will draw the button itself:
  71.     inherited::Draw(area);
  72.  
  73.     // Draw default border within clipping region of Button's Enclosure:
  74.     itsEnclosure->GetAperture(&enclAperture);
  75.     EnclToFrameR(&enclAperture);
  76.     FrameToWindR(&enclAperture, &windRect);        /* Controls use Window coords. */
  77.     ClipRect(&windRect);
  78.     
  79.     GetPenState(&savePenState);
  80.     portHasColor = CurrentPortHasColor();
  81.     if (portHasColor)        GetForeColor(&saveForeColor);
  82.     
  83.     defRect = (**macControl).contrlRect;
  84.     
  85.  /* Border is 3 pixels wide, outset from the button by 1 pixel.
  86.  ** The next three statements are accomplished by the DrawBorder
  87.  ** method.  The last is done by the above SetDefault method
  88.  ** which sets the roundDiameter parm passed to FrameRoundRect
  89.  ** within the DrawBorder routine:
  90.  
  91.     PenNormal();
  92.     PenSize(3, 3);
  93.     InsetRect(&defRect, -4, -4);
  94.     roundCorner = Max(height/2, 16);                            */
  95.     
  96.     /* Draw gray border for an inactive button: */
  97.     if ( !IsActive() )        SetGrayPen();
  98.     else if (portHasColor)    {
  99.         if (GetAuxCtl(macControl, &acHndl))        {
  100.             ccTable = (**acHndl).acCTable;
  101.             RGBForeColor(& ((**ccTable).ctTable)[cFrameColor].rgb );
  102.         }
  103.     }
  104.  
  105.     itsBorder->DrawBorder(&defRect);
  106.     
  107.     /* Avoid ugly flashes if there is also a pending
  108.     ** update event that will also draw this button:  */
  109.     itsBorder->CalcBorderRect(&defRect);
  110.     ValidRect(&defRect);
  111.     
  112.     if (portHasColor)        RGBForeColor(&saveForeColor);
  113.     SetPenState(&savePenState);
  114.  
  115. }    /* Draw */
  116.  
  117.  
  118.  
  119.  
  120. /* end: CDefaultButton.c */
  121.